package com.wit.witmg.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wit.witmg.entity.THr;
import com.wit.witmg.entity.TLogist;
import com.wit.witmg.mapper.TLogistMapper;
import com.wit.witmg.service.ITLogistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wit.witmg.util.ErrorCode;
import com.wit.witmg.util.JsonResult;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bob
 * @since 2025-02-24
 */
@Service
public class TLogistServiceImpl extends ServiceImpl<TLogistMapper, TLogist> implements ITLogistService {

    @Override
    public Object add(HttpServletRequest request, String json) {
        TLogist t= JSON.parseObject(json,TLogist.class);
        if(t.getId()>0){
            boolean bl=  updateById(t);
            if(!bl){
                return JsonResult.error(ErrorCode.ERR_200);
            }
        }else{
            boolean bl= save(t);
            if(!bl){
                return JsonResult.error(ErrorCode.ERR_504);
            }
        }
        return JsonResult.success(t);
    }

    @Override
    public Object get(HttpServletRequest request, String code0, String code1, String na, Integer id) {
        QueryWrapper<TLogist> qw=new QueryWrapper<>();
        if(id!=null){
            return JsonResult.success(getById(id));
        }
        if(code0!=null){
            qw.like("code0",code0);
        }else if(code1!=null){
            qw.like("code1",code1);
        }else if(na!=null){
            qw.like("na",na);
        }

        return JsonResult.success(list(qw));
    }
}
